import {getReq} from "./request"
import {httpUrl} from "./constant"
import {getQueryParams} from "./preset"

interface searchParam {
    page: number,// 当前页

    [propsName: string]: any
}

/**
 * 爬取数据
 * @param {searchParam} queryParam
 */
export const getSearch = async function (queryParam: searchParam): Promise<any> {
    const params = await getQueryParams({env: "search", params: queryParam});
    try {
        return await getReq(httpUrl.getData, {params})
    } catch (e) {
        return getSearch(queryParam)
    }
}

interface rateParam {
    page: number, // 当前页
    itemId: string, // 商品标识
    pageSize?: number, // 一页评论条数
    [propsName: string]: any
}

/**
 * 爬取评论
 * @param {rateParam} queryParam
 */
export const getRateList = async function (queryParam: rateParam): Promise<any> {
    const params = await getQueryParams({env: "rateList", params: queryParam});
    try {
        return await getReq(httpUrl.getRateList, {params})
    } catch (e) {
        return getRateList(queryParam)
    }
}